package com.ruoyi.binding.service.impl;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.binding.domain.JDP.Tools.OkHttpSessionClient;
import com.ruoyi.binding.domain.MhOrderRemote;
import com.ruoyi.binding.domain.MhOrderRemote;
import com.ruoyi.binding.mapper.MhOrderRemoteMapper;
import com.ruoyi.binding.service.IMhOrderRemoteService;
import com.ruoyi.common.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class MhOrderRemoteServiceImpl implements IMhOrderRemoteService {
    @Autowired
    private MhOrderRemoteMapper MhOrderRemoteMapper;

    @Autowired
    private MhSecJDPServiceImpl mhJDPService;


    @Autowired
    private OkHttpSessionClient client;

    /**
     * 查询数据汇总
     *
     * @param id 数据汇总主键
     * @return 数据汇总
     */
    @Override
    public MhOrderRemote selectMhOrderRemoteById(String id) {
        return MhOrderRemoteMapper.selectMhOrderRemoteById(id);
    }

    /**
     * 查询数据汇总列表
     *
     * @param MhOrderRemote 数据汇总
     * @return 数据汇总
     */
    @Override
    public List<MhOrderRemote> selectMhOrderRemoteList(MhOrderRemote MhOrderRemote) {
        return MhOrderRemoteMapper.selectMhOrderRemoteList(MhOrderRemote);
    }

    /**
     * 新增数据汇总
     *
     * @param MhOrderRemote 数据汇总
     * @return 结果
     */
    @Override
    public int insertMhOrderRemote(MhOrderRemote MhOrderRemote) {
        MhOrderRemote.setCreateTime(DateUtils.getNowDate());
        return MhOrderRemoteMapper.insertMhOrderRemote(MhOrderRemote);
    }

    /**
     * 修改数据汇总
     *
     * @param MhOrderRemote 数据汇总
     * @return 结果
     */
    @Override
    public int updateMhOrderRemote(MhOrderRemote MhOrderRemote) {
        MhOrderRemote.setUpdateTime(DateUtils.getNowDate());
        return MhOrderRemoteMapper.updateMhOrderRemote(MhOrderRemote);
    }

    /**
     * 批量删除数据汇总
     *
     * @param ids 需要删除的数据汇总主键
     * @return 结果
     */
    @Override
    public int deleteMhOrderRemoteByIds(String[] ids) {
        return MhOrderRemoteMapper.deleteMhOrderRemoteByIds(ids);
    }




    /**
     * @return
     */
    @Override
    public List<String> getGameType() throws Exception {
        List<String> resultList = new ArrayList<>();
        mhJDPService.login(client);
        JSONArray gameTypeResult = mhJDPService.queryGameType(client).getJSONArray("data");
        for (int i = 0; i < gameTypeResult.size(); i++) {
            JSONObject jsonObject = gameTypeResult.getJSONObject(i);
            resultList.add(jsonObject.getString("gameName"));
        }
        return resultList;
    }

}
